<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Banda extends CI_Controller {
    
        public function __construct() {
        parent::__construct();
        $this->load->library('form_validation');
        }
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
              
        $data = array(
            'n_banda' => $this->input->post("N_banda"),
            'nombre_b' => $this->input->post("Nombre"),
            'n_miembros' => $this->input->post("N_miembro"),   
            );
                        
            $tipo_op = $this->input->post("Operacion");
         
                switch ($tipo_op ) {
                    case "Insertar":
                    {
                        
                        $this->form_validation->set_error_delimiters('<span class="mensaje-error">', '</span>');
                            if ($this->form_validation->run('Banda') === FALSE) {

                                $this->load->view('dbwindows/Banda');
                                
                            } else {                                
                                $this->load->model('bandaDB');
                                $this->bandaDB->Insert_Tab($data);                                
                                $this->load->view('Clean/Banda', $data);
                            }
                    }
                        break;
                    case "Actualizar":
                    {
                      
                        $this->form_validation->set_error_delimiters('<span class="mensaje-error">', '</span>');
                            if ($this->form_validation->run('updBanda') === FALSE) {
                                $this->load->view('dbwindows/Banda');
                            } else {                                   
                            $this->load->model('bandaDB');
                            if ($this->bandaDB->update_entryband($data))
                                $this->load->view('Clean/Banda');
                            else
                                echo "Codigo no coindice, vaya atras en su navegador";    
                            }
                        
                        
                        
                    }
                        break;
                    case "Eliminar":
                    {
                        
                       $borrar = array (
                    'eliminar' => $this->input->post("N_banda"),            
                      ); // NOMBRE DEL INPUT COD o Ficha
                    
                    
                     
                    $this->form_validation->set_error_delimiters('<span class="mensaje-error">', '</span>');
                            if ($this->form_validation->run('Eliminarbanda') === FALSE) {
                                $this->load->view('dbwindows/Banda');
                            } else {
                                $this->load->model('BandaDB');     
                                    if ($this->BandaDB->borrar_tablabanda($borrar))
                                        $this->load->view('Clean/Banda',$data);
                                    else   {         
                                        echo "Ficha o Codigo inexistente en la relacion o tabla" ;
                                    ?>
                                    <br>
                                    <?php
                                        echo "Haga atras en su navegador para continuar"; 
                                    }
                            }  
                         
                        
                    }
                        break;
                    default:
                        echo "nothing happens";
                }
            
            
        
        
	}      
              
}
